package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Product;
import cn.wolfcode.crm.mapper.ProductMapper;
import cn.wolfcode.crm.query.ProductQueryObejct;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IProductService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
public class ProductServiceImpl implements IProductService {
    @Autowired
    private ProductMapper productMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return productMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Product record) {

        record.setIncom(new Date());
        BigDecimal cosePrice = record.getCosePrice();
        System.out.println("===============================");
        System.out.println(cosePrice);



        return productMapper.insert(record);
    }

    @Override
    public Product selectByPrimaryKey(Long id) {
        return productMapper.selectByPrimaryKey(id);

    }

    @Override
    public List<Product> selectAll() {
        return null;
    }

    @Override
    public int updateByPrimaryKey(Product record) {
        productMapper.updateByPrimaryKey(record);
        return 0;
    }

    @Override
    public PageResult query(QueryObject qo) {
        //查总记录数,
        int total = productMapper.queryForCount(qo);
        //查数据
        List<Product> rows = productMapper.queryForList(qo);
        return new PageResult(total,rows);
    }

    /*查询列表的数据*/
    @Override
    public List queryForList(ProductQueryObejct qo) {
        List<Product> rows = productMapper.queryForList(qo);
        return rows;
    }

    @Override
    public List<Product> listAll() {
        return productMapper.selectAll();
    }
}
